package com.lanchetech.user.controller;

import com.lanchetech.bean.request.*;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.BlogDetailVO;
import com.lanchetech.bean.vo.BlogVO;
import com.lanchetech.bean.vo.CommonCommentVO;
import com.lanchetech.entity.BlogCollect;
import com.lanchetech.entity.CommonComment;
import com.lanchetech.entity.TagCategory;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "博文接口", tags = "博文接口")
@RequestMapping("/api/blog")
@RestController
public class BlogController {

    @Autowired
    BlogService blogService;

    @ApiOperation("获取博文分页")
    @PostMapping("/getBlogPage")
    public ResultData<BasePageResp<BlogVO>> getBlogPage(@RequestBody BlogPageReq req,@AuthenticationPrincipal User user) {
        return blogService.getBlogPage(req,user);
    }

    @ApiOperation("获取我的博文分页")
    @PostMapping("/getMyBlogPage")
    public ResultData<BasePageResp<BlogVO>> getMyBlogPage(@RequestBody BlogPageReq req) {
        return blogService.getMyBlogPage(req);
    }

    @ApiOperation("获取博文详情")
    @GetMapping("/getBlogDetail")
    public ResultData<BlogDetailVO> getBlogDetail(@RequestParam("id") Long id) {
        return blogService.getBlogDetail(id);
    }

    @ApiOperation("博文点赞")
    @GetMapping("/editBlogGoods")
    public BaseResp editBlogGoods(@RequestParam("id") Long id) {
        return blogService.editBlogGoods(id);
    }

    @ApiOperation("获取点赞作品分页")
    @PostMapping("/getGoodsBlogPage")
    public ResultData<BasePageResp<BlogVO>> getGoodsBlogPage(@RequestBody BlogGoodsPageReq req) {
        return blogService.getGoodsBlogPage(req);
    }

    @ApiOperation("博文收藏")
    @GetMapping("/editBlogCollect")
    public BaseResp editBlogCollect(@RequestParam("id") Long id) {
        return blogService.editBlogCollect(id);
    }

    @ApiOperation("获取收藏作品分页")
    @PostMapping("/getCollectBlogPage")
    public ResultData<BasePageResp<BlogVO>> getCollectBlogPage(@RequestBody BlogCollectPageReq req) {
        return blogService.getCollectBlogPage(req);
    }

    @ApiOperation("编辑博文")
    @PostMapping("/editBlog")
    public BaseResp editBlog(@RequestBody BlogReq blog) {
        return blogService.editBlog(blog);
    }

    @ApiOperation("获取博文草稿")
    @GetMapping("/getBlogDraft")
    public ResultData<BlogDetailVO> getBlogDraft(@AuthenticationPrincipal User user) {
        return blogService.getBlogDraft(user);
    }

    @ApiOperation("删除博文")
    @GetMapping("/deleteBlog")
    public BaseResp deleteBlog(@RequestParam("id") Long id) {
        return blogService.deleteBlog(id);
    }

    @ApiOperation("获取标签类目列表")
    @GetMapping("/getTagCategoryList")
    public ResultData<List<TagCategory>> getTagCategoryList(@RequestParam("pid") Long pid) {
        return blogService.getTagCategoryList(pid);
    }

    @ApiOperation("获取所有标签类目列表")
    @GetMapping("/getAllTagCategoryList")
    public ResultData<List<TagCategory>> getAllTagCategoryList() {
        return blogService.getAllTagCategoryList();
    }

    @ApiOperation("发表评论")
    @PostMapping("/editCommonComment")
    public ResultData<Long> editCommonComment(@RequestBody CommonComment req) {
        return blogService.editCommonComment(req);
    }

    @ApiOperation("获取评论分页")
    @PostMapping("/getCommonCommentPage")
    public ResultData<BasePageResp<CommonCommentVO>> getCommonCommentPage(@RequestBody PageReq req) {
        return blogService.getCommonCommentPage(req);
    }

    @ApiOperation("点赞评论")
    @GetMapping("/editCommonCommentGoods")
    public BaseResp editCommonCommentGoods(@RequestParam("id") Long id) {
        return blogService.editCommonCommentGoods(id);
    }

    @ApiOperation("删除评论")
    @GetMapping("/deleteCommonComment")
    public BaseResp deleteCommonComment(@RequestParam("id") Long id) {
        return blogService.deleteCommonComment(id);
    }

}
